﻿using System;
using System.Collections.Generic;
using Ext.Net;
using BLL;
using Model;
using System.Xml;
using System.Xml.Xsl;

namespace Web.View.t104Menu
{
    public partial class Default : UIPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        //绑定Grid
        protected void t104_DataBind(object sender, StoreRefreshDataEventArgs e)
        {
            t104Mgr mgr = new t104Mgr();
            e.Total = int.Parse(mgr.GetRecordCount_t104(e.Parameters[t104_Filter.ParamPrefix]));
            IList<t104> list = mgr.FindAllByPage_t104(e.Start.ToString(), e.Limit.ToString(), e.Parameters[t104_Filter.ParamPrefix]);
            t104_MainStore.DataSource = list;
            t104_MainStore.DataBind();
        }
        //删除数据
        protected void BtnDel_Click(object sender, DirectEventArgs e)
        {
            t104Mgr mgr = new t104Mgr();
            RowSelectionModel sm = t104_Grid.SelectionModel.Primary as RowSelectionModel;
            foreach (SelectedRow row in sm.SelectedRows)
            {
                t104 _t104 = new t104();
                _t104.t104_00 = row.RecordID;//int.Parse(row.RecordID);
                if (mgr.Del_t104(_t104))
                {
                    log.Debug("t104中执行了删除，并成功");
                    X.Msg.Notify("成功", "<font color='green'>已经成功删除选中的记录</font>").Show();
                }
                else
                    X.Msg.Notify("失败", "<font color='green'>删除记录失败，请您重试！</font>").Show();
            }
            t104_Grid.Reload();
        }
        protected void BtnSave_Click(object sender, DirectEventArgs e)
        {
            t104Mgr mgr = new t104Mgr();
            t104 _t104 = new t104();
            if (Hid.Text.Length > 0)
                _t104 = mgr.FindById_t104(int.Parse(Hid.Text));
            
			_t104.t104_01 = Txtt104_01.Text.Trim();
			_t104.t104_02 = Txtt104_02.Text.Trim();
			_t104.t104_03 = Txtt104_03.Text.Trim();
			_t104.t104_04 = Txtt104_04.Text.Trim();
			_t104.t104_05 = Txtt104_05.Text.Trim();
			_t104.t104_06 = Txtt104_06.Text.Trim();
			_t104.t104_07 = Txtt104_07.Text.Trim();
			_t104.t104_08 = Txtt104_08.Text.Trim();
			_t104.t104_70 = Txtt104_70.Text.Trim();
			_t104.t104_09 = Txtt104_09.Text.Trim();
			_t104.t104_31 = Txtt104_31.Text.Trim();
			_t104.t104_10 = Txtt104_10.Text.Trim();
			_t104.t104_11 = Txtt104_11.Text.Trim();
			_t104.t104_12 = Txtt104_12.Text.Trim();
			_t104.t104_13 = Txtt104_13.Text.Trim();
			_t104.t104_14 = Txtt104_14.Text.Trim();
			_t104.t104_71 = Txtt104_71.Text.Trim();
			_t104.t104_15 = Txtt104_15.Text.Trim();
			_t104.t104_16 = Txtt104_16.Text.Trim();
			_t104.t104_17 = Txtt104_17.Text.Trim();
			_t104.t104_18 = Txtt104_18.Text.Trim();
			_t104.t104_19 = Txtt104_19.Text.Trim();
			_t104.t104_20 = Txtt104_20.Text.Trim();
			_t104.t104_21 = Txtt104_21.Text.Trim();
			_t104.t104_22 = Txtt104_22.Text.Trim();
			_t104.t104_23 = Txtt104_23.Text.Trim();
			_t104.t104_24 = Txtt104_24.Text.Trim();
			_t104.t104_25 = Txtt104_25.Text.Trim();
			_t104.t104_26 = Txtt104_26.Text.Trim();
			_t104.t104_27 = Txtt104_27.Text.Trim();
			_t104.t104_28 = Txtt104_28.Text.Trim();
			_t104.t104_29 = Txtt104_29.Text.Trim();
			_t104.t104_30 = Txtt104_30.Text.Trim();
			_t104.collection_time = Txtcollection_time.Text.Trim();

            bool isok = false;
            if (Hid.Text.Length > 0)
                isok = mgr.Update_t104(_t104);
            else
                isok = mgr.Add_t104(_t104);
            if (isok)
            {
                t104_Win.Hide();
                X.Msg.Notify("成功", "<font color='green'>恭喜您，操作成功！</font>").Show();
                log.Debug("t104中执行了保存（插入或修改），并成功");
                t104_Grid.Reload();
            }
            else
                X.Msg.Notify("失败", "<font color='red'>操作失败，请您重试！</font>").Show();
        }
        //数据保存为Excel
        protected void BtnSaveToExcel(object sender, EventArgs e)
        {
            string json = ExcelGridData.Value.ToString();
            StoreSubmitDataEventArgs eSubmit = new StoreSubmitDataEventArgs(json, null);
            XmlNode xml = eSubmit.Xml;
            this.Response.Clear();
            this.Response.ContentType = "application/vnd.ms-excel";
            this.Response.AddHeader("Content-Disposition", "attachment; filename=QiDian10Excel.xls");
            XslCompiledTransform xtExcel = new XslCompiledTransform();
            xtExcel.Load(Server.MapPath("/View/ExcelTemp/Excel.xsl"));
            xtExcel.Transform(xml, null, this.Response.OutputStream);
            this.Response.End();

        }
    }
}